//////////////////////////////////////////ok
#include"stdafx.h"

#include "bochs.h"

void IA32_CPU::MOV_RLIb(Ia32_Instruction_c *i)
{
  IA32_READ_8BIT_REGx(i->opcodeReg(),i->extend8bitL()) = i->Ib();
}

void IA32_CPU::MOV_RHIb(Ia32_Instruction_c *i)
{
   gen_reg[i->b1() & 0x03].word.byte.rh = i->Ib();
}

void IA32_CPU::MOV_EEbGb(Ia32_Instruction_c *i)
{
  write_virtual_byte(i->seg(), IA32_RMAddr(i), &IA32_READ_8BIT_REGx(i->nnn(),i->extend8bitL()));
}

void IA32_CPU::MOV_EGbGb(Ia32_Instruction_c *i)
{
  Bit8u op2 = IA32_READ_8BIT_REGx(i->nnn(),i->extend8bitL());
  IA32_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), op2);
}

void IA32_CPU::MOV_GbEEb(Ia32_Instruction_c *i)
{
  read_virtual_byte(i->seg(), IA32_RMAddr(i), &IA32_READ_8BIT_REGx(i->nnn(),i->extend8bitL()));
}

void IA32_CPU::MOV_GbEGb(Ia32_Instruction_c *i)
{
  Bit8u op2 = IA32_READ_8BIT_REGx(i->rm(),i->extend8bitL());
  IA32_WRITE_8BIT_REGx(i->nnn(), i->extend8bitL(), op2);
}

void IA32_CPU::MOV_ALOb(Ia32_Instruction_c *i)
{
  read_virtual_byte(i->seg(), i->Id(), &AL);
}

void IA32_CPU::MOV_ObAL(Ia32_Instruction_c *i)
{
  write_virtual_byte(i->seg(), i->Id(), &AL);
}

void IA32_CPU::MOV_EbIb(Ia32_Instruction_c *i)
{
  Bit8u op2 = i->Ib();

  if (i->modC0()) 
  {
    IA32_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), op2);
  }
  else 
  {
    write_virtual_byte(i->seg(), IA32_RMAddr(i), &op2);
  }
}

void IA32_CPU::XLAT(Ia32_Instruction_c *i)
{
  Bit32u offset_32;

  if (i->as32L()) 
  {
    offset_32 = EBX + AL;
  }
  else
  {
    offset_32 = BX + AL;
  }

  if (!IA32_NULL_SEG_REG(i->seg())) 
  {
    read_virtual_byte(i->seg(), offset_32, &AL);
  }
  else 
  {
    read_virtual_byte(IA32_SEG_REG_DS, offset_32, &AL);
  }
}

void IA32_CPU::XCHG_EbGb(Ia32_Instruction_c *i)
{
  Bit8u op2, op1;
  op2 = IA32_READ_8BIT_REGx(i->nnn(), i->extend8bitL());

  if (i->modC0()) 
  {
    op1 = IA32_READ_8BIT_REGx(i->rm(), i->extend8bitL());
    IA32_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), op2);
  }
  else 
  {
    read_RMW_virtual_byte(i->seg(), IA32_RMAddr(i), &op1);
    write_RMW_virtual_byte(op2);
  }
  IA32_WRITE_8BIT_REGx(i->nnn(), i->extend8bitL(), op1);
}
